#include "producer.h"
#include "consumer.h"
#include <QDebug>
#include <QSemaphore>

#define SIZE 50
QSemaphore freeByte(SIZE);
QSemaphore useByte(0);

Producer::Producer()
{

}
void Producer::run()
{
	for(int i=0; i<SIZE; i++)
	{
		freeByte.acquire();
		qDebug()<<"produer:"<<i;
		useByte.release();
		sleep(1);
	}
}
Consumer::Consumer()
{

}
void Consumer::run()
{
	for(int i=0; i<SIZE; i++)
	{
		useByte.acquire();
		qDebug()<<"consumer:"<<i;
		freeByte.release();
		sleep(2);
	}
}
